package com.zcyr.core.sql.statement;

import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.statement.SQLCreateDatabaseStatement;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.zcyr.core.sql.visitor.OGASTVisitor;
import com.zcyr.core.sql.visitor.OGOutputVisitor;

/**
 * 适用于opengauss的create schema statement
 */
public class OGCreateSchemaStatement extends SQLCreateDatabaseStatement {

    public OGCreateSchemaStatement(String dbType) {
        super (dbType);
    }

    public SQLName getSchema() {
        return getName();
    }

    public void setSchema(SQLName schema) {
        if (schema != null) {
            schema.setParent(this);
        }
        setName(schema);
    }

    protected void accept0(SQLASTVisitor visitor) {
        if (visitor instanceof OGASTVisitor) {
            accept0((OGASTVisitor) visitor);
        } else {
            super.accept0(visitor);
        }
    }

    public void accept0(OGASTVisitor visitor) {
        if (visitor.visit(this)) {
            acceptChild(visitor, this.getName());
        }
        visitor.endVisit(this);
    }

    public String toString(){
        StringBuilder out = new StringBuilder();
        this.accept(new OGOutputVisitor(out));
        return out.toString();
    }
}
